package com.txl.seckill.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;



@Component
public class MD5Util {

    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    private static final String salt="1a2b3c4d";
    //前端-->后端
    private static String inputPassToFormPass(String inputPass){
        String str = salt.charAt(0)+salt.charAt(2)+salt.charAt(4)+inputPass+salt.charAt(3)+salt.charAt(5)+salt.charAt(7);
        return md5(str);
    }
    //后端-->数据库
    public static String formPassToDBPass(String formPass,String salt){
        String str = salt.charAt(0)+salt.charAt(2)+salt.charAt(4)+formPass+salt.charAt(3)+salt.charAt(5)+salt.charAt(7);
        return md5(str);
    }
    /**调用方法:
     * 前端-->数据库
     */
    public static String inputPassToDBPass(String inputPass,String salt){
        String formPass = inputPassToFormPass(inputPass);
        String dbPass = formPassToDBPass(formPass, salt);
        return dbPass;
    }

    //测试
    public static void main(String[] args) {
        String pass ="13579246";
        String salt ="12345678";
        String dbpass = inputPassToDBPass(pass,salt);
        System.out.println(dbpass);
    }



}
